<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/5/005
 * Time: 11:48
 */

namespace app\api\controller\v1;

use app\api\controller\BaseController;
use app\api\model\Banner as BannerModel;
use app\api\model\Product as ProductModel;
use app\lib\exception\BannerException;
use app\lib\exception\ProductException;

class Index extends BaseController {

    /**
     * 获取首页数据
     * @return array
     * @throws BannerException
     * @throws ProductException
     */
    public function index() {

        $banner = BannerModel::getBannerList();
        if (!$banner) {
            throw new BannerException();
        }

        $product = ProductModel::getIndexProduct();
        if (!$product) {
            throw new ProductException([
                'msg' => '首页产品数据异常',
                'errorCode' => 80001
            ]);
        }

        return [
            'banner' => $banner,
            'product' => $product
        ];
    }
}